import request from '@/utils/request'
import {
	toast
} from '@/utils/common.js'
import {
	showConfirm
} from '@/utils/common'
// 获取openId
export function getOpenId(data) {
	return request({
		url: '/wx/user/code',
		method: 'post',
		data: data
	})
}

// 注册会员
export function register(data) {
	debugger
	return request({
		url: '/wx/user/register',
		method: 'post',
		data: data
	})
}

//获取手机号
export function getPhoneNum(data) {
	return request({
		url: '/wx/user/getPhoneNumber',
		method: 'post',
		data: data
	})
}

//获取用户信息
export function getWxUser(data) {
	return request({
		url: '/wx/user/getWxUser',
		method: 'post',
		data: data
	})
}

// 手机号授权解密
export function decryptPhoneNum(data) {
	return request({
		url: '/marketing/common/mobileAuthorization',
		method: 'post',
		data: data
	})
}
// 获取站点列表
export function getListStation(data) {
	return request({
		url: '/wx/charge/listStation',
		method: 'post',
		data: data
	})
}
// 获取站点信息
export function getStationInfo(data) {
	return request({
		url: '/wx/charge/stationInfo',
		method: 'post',
		data: data
	})
}
// 获取电枪+站点信息
export function getGunOrStationInfo(data) {
	return request({
		url: '/wx/charge/getInfoByConnectorId',
		method: 'post',
		data: data
	})
}
// 开始充电
export function startCharge(data) {
	return request({
		url: '/wx/charge/start',
		method: 'post',
		data: data
	})
}
// 查询充电状态
export function chargeStatus(data) {
	return request({
		url: '/wx/charge/status',
		method: 'post',
		data: data
	})
}
// 停止充电
export function chargeStop(data) {
	return request({
		url: '/wx/charge/stop',
		method: 'post',
		data: data
	})
}
// 充电完成查询订单详情
export function completeChargeOrderDetails(data) {
	return request({
		url: '/wx/charge/getOrder',
		method: 'post',
		data: data
	})
}
// 登录/注册/获取会员信息
export function createMemberInfo(data) {
	return request({
		url: `/wx/user/getInfo/${data.openId}`,
		method: 'get',
		// data: data
	})
}

export function fuelOrders(data) {
	return request({
		url: '/wx/fuel/orders',
		method: 'get',
		data: data
	})
}

export function getInfoUser(data) {
	return request({
		url: `/wx/user/getInfo/${data.openId}`,
		method: 'get',
		data: data
	})
}



export function getMember(data) {
	return new Promise(function(ressolve, reject) {
		getInfoUser(data).then(res => {
			uni.setStorageSync('memberInfo', JSON.stringify(res))
			ressolve(res)
		}).catch(err => {
			uni.removeStorageSync('memberInfo')
			if (err != 200) {
				toast('请求失败,请重试')
			}
			reject(err)
		})
	})
	// request({
	// 	method: 'get',
	// 	url: `/wx/user/getInfo/${data.openId}`,
	// }).then(res => {
	// 	uni.setStorageSync('memberInfo', JSON.stringify(res))
	// }).catch(err => {
	// 	uni.removeStorageSync('memberInfo')
	// 	if (err != 200) {
	// 		toast('请求失败,请重试')
	// 	}
	// })
}


export function getCode() {
	return new Promise(function(resolve, reject) {
		let FUELORCHARGE = uni.getStorageSync('FUELORCHARGE')
		let isCode = uni.getStorageSync('isCode')
		if (FUELORCHARGE || isCode) {
			uni.login({
				provider: 'weixin', // 使用微信登录
				success: function(loginRes) {
					console.log(loginRes);
					getOpenId({
						code: loginRes.code,
					}).then(res => {
						resolve(res)
						if (res) {
							uni.setStorageSync('userOpenId', res.openid)
							uni.setStorageSync('userToken', res.sessionKey + res.openid)
						}
					}).catch(error => {
						reject(error)
						if (error != 200) {
							toast('请求失败,请重试')
							return
						}
					})
				}
			})
		}
	})
}

// 查看充电订单
export function checkChargeOrders(data) {
	return request({
		url: '/wx/charge/orders',
		method: 'post',
		data: data
	})
}
// 查看充电中的订单
export function checkChargrHaveOrders(data) {
	return request({
		url: '/wx/charge/incomplete',
		method: 'post',
		data: data
	})
}
// 特来电授权接口
export function chargeAuth(data) {
	return request({
		url: '/wx/charge/auth',
		method: 'post',
		data: data
	})
}
/* ************************************************************************************************** */
// 获取加油站点列表
export function getListFuelStation(data) {
	return request({
		url: '/wx/fuel/listStation',
		method: 'post',
		data: data
	})
}
// 获取加油站点详情
export function getFuelStationInfo(data) {
	return request({
		url: '/wx/fuel/stationInfo',
		method: 'post',
		data: data
	})
}
// 获取最近一笔加油未支付订单
export function getLastFuelUnpaidOrder(data) {
	return request({
		url: '/wx/fuel/nozLastUnPayOrder',
		method: 'post',
		data: data
	})
}

// 收支明细
export function listHistAmt(data) {
	return request({
		url: '/wx/user/listHistAmt',
		method: 'post',
		data: data
	})
}
// 获取加油订单优惠
export function getFuelOrderDisc(data) {
	return request({
		url: '/wx/fuel/getDisc',
		method: 'post',
		data: data
	})
}
// 加油订单支付
export function payFuelOrder(data) {
	return request({
		url: '/wx/fuel/pay',
		method: 'post',
		data: data
	})
}
// 加油订单支付信息
export function getFuelOrderInfo(data) {
	return request({
		url: '/wx/fuel/orderInfo',
		method: 'post',
		data: data
	})
}

// 完善信息
export function editUserInfo(data) {
	return request({
		url: '/wx/user/editInfo',
		method: 'post',
		data: data
	})
}

// 绑定企业子卡
export function bindCompanyCard(data) {
	return request({
		url: '/wx/user/bindCompanyCard',
		method: 'post',
		data: data
	})
}

// 能量卡绑定
export function bindPowerCard(data) {
	return request({
		url: '/wx/user/bindPowerCard',
		method: 'post',
		data: data
	})
}

//优惠券列表
export function listCoupon(data) {
	return request({
		// url: '/wx/market/listCoupon',
		url: '/wx/market/userCouponPage',
		method: 'post',
		data: data
	})
}
export function miniPay(data) {
	return request({
		url: '/wx/pay',
		method: 'post',
		data: data
	})
}

export function createRechargeOrder(data) {
	return request({
		url: '/wx/user/createRechargeOrder',
		method: 'post',
		data: data
	})
}


//加油广告
export function fuelListAdv(data) {
	return request({
		url: '/wx/fuel/listAdv',
		method: 'post',
		data: data
	})
}
//充电广告
export function chargeListAdv(data) {
	return request({
		url: '/wx/charge/listAdv',
		method: 'post',
		data: data
	})
}

//获取洗车券
export function getWashCoupon(data) {
	return request({
		url: '/wx/market/getWashCoupon',
		method: 'post',
		data: data
	})
}

//核销洗车券
export function useWashCoupon(data) {
	return request({
		url: '/wx/market/useWashCoupon',
		method: 'post',
		data: data
	})
}

//付款码  
export function payCode(data) {
	return request({
		url: '/wx/user/randomPayCode',
		method: 'get',
		data: data
	})
}


//加油码
export function fuelCode(data) {
	return request({
		url: '/wx/user/fuelCode',
		method: 'post',
		data: data
	})
}


//积分列表
export function giftList(data) {
	return request({
		url: '/wx/market/gift/list',
		// url: '/wx/market/gift/list ',
		method: 'post',
		data: data
	})
}

export function getGiftStationList(data) {
	return request({
		url: '/wx/market/gift/stationList',
		method: 'post',
		data: data
	})
}

//兑换商品
export function giftExchange(data) {
	return request({
		// url: '/wx/market/gift/exchange',
		url: '/wx/market/gift/exchangeV2',
		method: 'post',
		data: data
	})
}

export function randomPayCodeQr() {
	return request({
		url: '/wx/user/randomPayCodeQr',
		method: 'get',
	})
}

//充值退款
export function wxRefund(data) {
	return request({
		url: '/wx/user/refund',
		method: 'post',
		data:data
	})
}

//自助支付创建订单
export function createdOrder(data) {
	return request({
		url: '/wx/market/shop/createdOrder',
		method: 'post',
		data: data
	})
}


//充值订单
export function rechargeOrder(data) {
	return request({
		url: '/wx/recharge/orders',
		method: 'get',
		data: data
	})
}

//创建抬头
export function saveInvoiceTitle(data) {
	return request({
		url: '/wx/invoice/header/saveOrUpdate',
		method: 'post',
		data: data
	})
}

//发票抬头列表
export function getInvoiceTitle(data) {
	return request({
		url: '/wx/invoice/header/list',
		method: 'post',
		data: data
	})
}

//删除发票抬头
export function deleteInvoiceTitle(data) {
	return request({
		url: '/wx/invoice/header/deleteById',
		method: 'post',
		data: data
	})
}

//待开票订单列表
export function getInvoiceOrderList(data) {
	return request({
		url: '/wx/invoice/orderToInvoiceList',
		method: 'post',
		data: data
	})
}

//开票历史
export function getInvoiceHistoryList(data) {
	return request({
		url: '/wx/invoice/historyList',
		method: 'post',
		data: data
	})
}

//开票申请
export function applyInvoice(data) {
	return request({
		url: '/wx/invoice/apply',
		method: 'post',
		data: data
	})
}

//发票详情
export function invoiceDetail(data) {
	return request({
		url: '/wx/invoice/detail',
		method: 'post',
		data: data
	})
}

//发票详情 订单列表
export function invoiceDetailOrderList(data) {
	return request({
		url: '/wx/invoice/orderList',
		method: 'post',
		data: data
	})
}

//申请作废
export function repealApply(data) {
	return request({
		url: '/wx/invoice/repealApply',
		method: 'post',
		data: data
	})
}

//券码核销
export function verifyCoupon(data) {
	return request({
		url: '/wx/market/verifyUserCoupon',
		method: 'post',
		data: data
	})
}


//券码核销
export function getPointList(data) {
	return request({
		url: '/wx/market/pointHistory',
		method: 'post',
		data: data
	})
}

//券码核销
export function getEmpCard(data) {
	return request({
		url: '/wx/user/isChildrenAcc',
		method: 'post',
		data: data
	})
}